﻿Imports System.Data.OleDb
Public Class View
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' If Not Page.IsPostBack Then


        Dim dataSet As New DataSet()
        Dim sqlCommand = "select * from Restaurant where RestaurantID=" & Request.QueryString("id")
        Dim oleDataAdapter As New OleDb.OleDbDataAdapter(sqlCommand, ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)
        oleDataAdapter.Fill(dataSet, "Restaurant")
        dataList.DataSource = dataSet.Tables("Restaurant").DefaultView
        dataList.DataBind()
        Dim dataSetComment As New DataSet()

        sqlCommand = "select * from Comments where RestaurantID='" & Request.QueryString("id") & "'"
        Dim oleDataAdapterComment As New OleDb.OleDbDataAdapter(sqlCommand, ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)
        oleDataAdapterComment.Fill(dataSetComment, "Comments")
        dataListComment.DataSource = dataSetComment.Tables("Comments").DefaultView
        dataListComment.DataBind()
        ' End If
    End Sub

    Protected Sub BtAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtAdd.Click
        If Session("Login").ToString = "False" Then
            LbResult.Text = "Please login to comment"
        Else

            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)


            oleDbConn.Open()
            Dim cmdQuery As String
            cmdQuery = "insert into Comments (CommentTitle,CommentBody,UserName,RestaurantID)" &
                " VALUES('" & TbTitle.Text.ToString().Replace("'", "''") & "','" & TbBody.Text.ToString().Replace("'", "''") & "','" & Session("Username").ToString & "','" & Request.QueryString("id") & "')"

            Dim dbcomm = New OleDbCommand(cmdQuery, oleDbConn)
            dbcomm.ExecuteNonQuery()
            oleDbConn.Close()
            Dim dataSetComment As New DataSet()

            Dim sqlCommand = "select * from Comments where RestaurantID='" & Request.QueryString("id") & "' order by RestaurantID desc"
            Dim oleDataAdapterComment As New OleDb.OleDbDataAdapter(sqlCommand, ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)
            oleDataAdapterComment.Fill(dataSetComment, "Comments")
            dataListComment.DataSource = dataSetComment.Tables("Comments").DefaultView
            dataListComment.DataBind()

        End If

    End Sub
End Class